﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GovernmentOfficeProject.LevelDataAccessModel;
using GovernmentOfficeProject.LevelDataAccess;

namespace GovernmentOfficeProject.LevelBusinessLogic
{
    public class BLL_UserRelation
    {
        public bool deleteRelationByRelationID(decimal relationID)
        {
            try
            {
                return new DAL_USER_Relation().deleteRelationByRelationID(relationID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public List<Entity_USER_Relation> getRelationListByMasterUserID(decimal masterUserID)
        {
            try
            {
                Entity_USER_Relation relEntityParameter = new Entity_USER_Relation();
                relEntityParameter.UrMasterUserID = masterUserID;
                return new DAL_USER_Relation().getRelationListByRelationEntity(relEntityParameter);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public List<Entity_USER_Relation> getRelationListByMasterUIDAndControlledUID(decimal masterUserID,decimal controlledUserID)
        {
            try
            {
                Entity_USER_Relation relEntityParameter = new Entity_USER_Relation();
                relEntityParameter.UrMasterUserID = masterUserID;
                relEntityParameter.UrControlledUserID = controlledUserID;
                return new DAL_USER_Relation().getRelationListByRelationEntity(relEntityParameter);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public Entity_USER_Relation getRelationEntityByMasterUIDAndControlledUIDAndPrivilegeID(decimal masterUserID, decimal controlledUserID,decimal privilegeID)
        {
            try
            {
                Entity_USER_Relation relEntityParameter = new Entity_USER_Relation();
                relEntityParameter.UrMasterUserID = masterUserID;
                relEntityParameter.UrControlledUserID = controlledUserID;
                relEntityParameter.UrControlledPrivilegeID = privilegeID;
                List<Entity_USER_Relation> relationList = new DAL_USER_Relation().getRelationListByRelationEntity(relEntityParameter);
                Entity_USER_Relation relationReturn = null;
                foreach (Entity_USER_Relation relation in relationList)
                {
                    relationReturn = new Entity_USER_Relation();
                    relationReturn.UrID = relation.UrID;
                    relationReturn.UrMasterUserID = relation.UrMasterUserID;
                    relationReturn.UrControlledUserID = relation.UrControlledUserID;
                    relationReturn.UrControlledPrivilegeID = relation.UrControlledPrivilegeID;
                    relationReturn.UrStatus = relation.UrStatus;
                    relationReturn.UrBackup = relation.UrBackup;
                }
                return relationReturn;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        

        public bool addRelation(Entity_USER_Relation relationEntity)
        {
            try
            {
                return new DAL_USER_Relation().addRelation(relationEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public List<Entity_USER_Relation> getRelationListALL()
        {
            try
            {
                return new DAL_USER_Relation().getRelationList();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
    }
}
